package com.cius.util;

import com.cius.model.OrderState;
import org.apache.struts2.util.StrutsTypeConverter;

import java.util.Map;

/**
 * 订单状态类型转换器
 * Created by CiusCheung on 16/9/18.
 */
public class OrderStateConversion extends StrutsTypeConverter {
    @Override
    public Object convertFromString(Map arg0,String[] arg1,Class arg2){
        OrderState[] orderStates = OrderState.values();
        for (OrderState orderState : orderStates){
            if(orderState.getName().equals(arg1[0])){
                return orderState;
            }
        }
        return null;
    }

    @Override
    public String convertToString(Map arg0,Object arg1){
        OrderState orderState = (OrderState) arg1;
        return orderState.getName();
    }
}
